package im

import (
    "strconv"
	"dhfshop/models/im"
	"dhfshop/controllers/base"
)

type ChatSessionController struct {
	base.BaseController
}

func (this *ChatSessionController) List() {
	query,_,fields,order_by,offset,limit,err := this.GetQueryPara()
	if err != nil {
	   this.ServeError(err.Error())
	   return
	}
	partnerId := int64(this.Ctx.Input.GetData("curCompanyId").(int))
	query["partner_id"] = strconv.FormatInt(partnerId, 10)
	l, cnt, err := im.GetAllChatSessions(query,fields,order_by,offset,limit)
	if err != nil {
	    this.ServeError(err.Error())
		return
	}
	r := struct {
		TotalCount int64                `json:"total_count"`
	    ChatSessions  []*im.ChatSession `json:"chat_sessions"`
	}{TotalCount: cnt, ChatSessions: l}
	this.Data["json"] = r
	this.ServeJSON()
}
